﻿using ReflectionStudio.Core.Events;
using System;
using System.Data;
using System.Windows;
using System.Windows.Data;
using System.ComponentModel;
namespace WPFExcelReport
{
    public partial class TSKD09 : ViewBase
    {
        #region ==dwKDF===========
        public static readonly DependencyProperty dwKDFProperty = DependencyProperty.Register("dwKDF",
            typeof(DataRow), typeof(TSKD09),
            new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OdwKDFChanged));
        public DataRow dwKDF
        {
            get
            {
                return (DataRow)GetValue(dwKDFProperty);
            }
            set
            {
                SetValue(dwKDFProperty, value);
            }
        }
        private static void OdwKDFChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as TSKD09;
            if (src != null)
            {
                DataRow row = (DataRow)e.NewValue;
                src.dwKDF = row; 
            }
        }
        #endregion 
      #region ==dwKD===========
        public static readonly DependencyProperty dwKDProperty = DependencyProperty.Register("dwKD",
            typeof(DataRow), typeof(TSKD09),
            new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OdwKDChanged));
        public DataRow dwKD
        {
            get
            {
                return (DataRow)GetValue(dwKDProperty);
            }
            set
            {
                SetValue(dwKDProperty, value);
            }
        }
        private static void OdwKDChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as TSKD09;
            if (src != null)
            {
                DataRow row = (DataRow)e.NewValue;
                src.dwKD = row;
                src.Load(row);
            }
        }
        #endregion 
        
        #region ==KDF===========
        public static readonly DependencyProperty KDFProperty = DependencyProperty.Register("KDF",
            typeof(string), typeof(TSKD09),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnKDFChanged));
        public string KDF
        {
            get
            {
                return (string)GetValue(KDFProperty);
            }
            set
            {
                SetValue(KDFProperty, value);
            }
        }
        private static void OnKDFChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as TSKD09;
            if (src != null)
            {
                src.KDF = (string)e.NewValue; 
            }
        }
        #endregion
        public TSKD09()
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            MV = new VKUNDFORM(); 
            IsMasterFromMV = true;
            TBMain = MV.SetProd.Tables[TB];
            InitializeComponent();
        }
        public override void vwMaster_CurrentChanged(object sender, EventArgs e)
        {
            base.vwMaster_CurrentChanged(sender, e);
            dwKDF = dwMaster; 
        }
        DataSet SResult;
        DataRow dwData;
        public override void Window_Loaded(object sender, RoutedEventArgs e)
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            base.Window_Loaded(sender, e);
        }
        public void Locate()
        {

        } 

        public void Load(DataRow _dwKD)
        {
            if (_dwKD == null)
                return; 
            dwData = TBMain.NewRow(); 
            dwData["KDFMANDANT"] = app.Mandant;
            dwData["KDFKUNDNR"] = _dwKD["KDKUNDNR"];
            SResult = ((VKUNDFORM)MV).QueryKUNDFORM(dwData, -1);
            MergeData(SResult, true,true);
        } 
    }
}
